package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.android.kvdb.KVDB

import kotlinx.android.synthetic.main.activity_main.*
import java.io.File


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        textview.setText(R.string.app_name)

        var absolutePath = externalCacheDir?.absolutePath;
        absolutePath = absolutePath.plus(File.separator).plus("db");
        Log.d("MainActivity", absolutePath);

        val kvdb = KVDB.Builder(this.applicationContext)
            .withDBName("test_db.db").withDbPath(absolutePath)
            .build()
        KVDB.setSingletonInstance(kvdb)
        KVDB.setDebug(true)

//    textview.setOnClickListener{
//      KVDB.set(this.applicationContext,"Test","test")
//    }

        btn.setOnClickListener {
            textview.setText("Test")
            KVDB.setString(this.applicationContext, "Test", "test")
            KVDB.setString(this.applicationContext, "Test2", "test2")
            KVDB.setString(this.applicationContext, "Test3", "test2")
            KVDB.setString(this.applicationContext, "Test4", "test2")
            KVDB.remove(this.applicationContext, "Test2")
            KVDB.remove(this.applicationContext, "Test4")

        }

        btn2.setOnClickListener {
            val text = KVDB.getString(this.applicationContext, "Test")
            Log.d("", text)
            textview.setText(text)

            val editor=KVDB.editor(this);
            editor.putBoolean("test100",true)
                .putString("test101","test101")
                .putInt("testint",100)
                .remove("test1")
                .remove("test3")
                .commit();
            
        }

    }
}
